home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Samples / SampleCode / Unsupported Libraries / SetupPickPoint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-11  |  2.3 KB  |  84 lines  |  [TEXT/MPS ]

  1. /******************************************************************************
  2.  **                                                                             **
  3.  **     Module:        SetupPickPoint.c                                         **
  4.  **                                                                          **
  5.  **                                                                          **
  6.  **     Purpose:                                                               **
  7.  **                                                                          **
  8.  **                                                                          **
  9.  **                                                                          **
  10.  **     Copyright (C) 1992-1995 Apple Computer, Inc.  All rights reserved.     **
  11.  **                                                                          **
  12.  **     Change Log:                                                             **
  13.  **                                                                          **
  14.  **        01/21/94    pjs        Fixed picking.                                      **
  15.  **                                                                          **
  16.  *****************************************************************************/
  17. #include "QD3D.h"
  18. #include "SetupPickPoint.h"
  19. #include "QD3DMath.h"
  20. #include "QD3DCamera.h"
  21.  
  22.  
  23.  
  24. /*===========================================================================*\
  25.  *
  26.  *    Routine:    SetupPickPoint()
  27.  *
  28.  *    Comments:    
  29.  *
  30. \*===========================================================================*/
  31.  
  32. void SetupPickPoint(
  33.     WindowPtr        qdWindow,
  34.     TQ3Point2D        *pickPoint, 
  35.     TQ3CameraObject     camera, 
  36.     TQ3Point2D        *screenPoint)
  37. {
  38.     float                    xf, yf;
  39.     Rect                    r;
  40.     short                    width, height;
  41.     TQ3RationalPoint4D        worldPoint, localPoint;
  42.     TQ3Matrix4x4                wtfmatrix;
  43.     TQ3Point3D                camFrom;
  44.     TQ3CameraPlacement        camPlacementData;
  45.     
  46.     pickPoint;        /* unused argument */
  47.     screenPoint;    /* unused argument */
  48.     
  49.     r = qdWindow->portRect;
  50.     width = r.right - r.left;
  51.     height = r.bottom - r.top;
  52.     
  53.     xf = 0.0;        /* Julian, you have a bug here.  I've added these two lines */
  54.     yf = 0.0;        /* but you will need to change them to the appropriate        */
  55.                     /* values 5/15/94 brh */
  56.  
  57.     /* move from 0 to 1 skiashape space to -1 to 1 frustum space. */
  58.     localPoint.x = xf * 2.0 - 1.0;
  59.     localPoint.y = (1.0 - yf) * 2.0 - 1.0;        /* invert y */
  60.     localPoint.z = 0.0;
  61.     localPoint.w = 1.0;
  62.  
  63.     Q3Camera_GetWorldToFrustum(camera, &wtfmatrix);
  64.     Q3Matrix4x4_Invert(&wtfmatrix, &wtfmatrix);
  65.  
  66.     Q3RationalPoint4D_To4DTransformArray(&localPoint,
  67.                                  &wtfmatrix,
  68.                                  &worldPoint,
  69.                                  1,
  70.                                  sizeof(TQ3Point3D),
  71.                                  sizeof(TQ3Point3D));
  72.  
  73.     worldPoint.x /= worldPoint.w;
  74.     worldPoint.y /= worldPoint.w;
  75.     worldPoint.z /= worldPoint.w;
  76.  
  77.     
  78.     Q3Camera_GetPlacement(camera, &camPlacementData);
  79.  
  80.     camFrom = camPlacementData.cameraLocation;
  81.  
  82.     Q3Vector3D_Normalize((TQ3Vector3D *)&camFrom, (TQ3Vector3D *)&camFrom);
  83. }
  84.